﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using SimpleNoteLib.Config;
using SimpleNoteLib.HttpRequests;
using SimpleNoteLib.Json;

namespace SimpleNoteLib.ApiRequests
{
    internal class CreateNoteRequest : HttpPostRequest
    {
        public NoteJson NoteJson { get; set; }
        public string Email { get; set; }
        public string Token { get; set; }

        public CreateNoteRequest(NoteJson noteJson)
        {
            NoteJson = noteJson;
            Email = Login.Email;
            Token = Login.Token;
        }

        private void SetAddress()
        {
            Address = string.Format("{0}data?auth={1}&email={2}", SimpleNoteApiConfig.ApiAddress, Token, Email);
        }

        private void EncodeData()
        {
            //            string tmp = File.ReadAllText(@"d:\note.txt");
            Data = Encoding.UTF8.GetBytes(NoteJson.ToString());
        }

        public override string SendAndGetResponse()
        {
            SetAddress();
            EncodeData();
            return base.SendAndGetResponse();
        }
    }
}
